#region imported Namespaces
using System;
using System.Data;
using System.Data.SqlClient;

using BO = PHSRAG.Insight21.BusinessObjects;
using Utility = PHSRAG.Utility;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.Agreements
{
	/// <summary>
	/// The AgreementSummary class is the facade over the details for a single agreement summary.
	/// </summary>
	public class AgreementSummary : BO.BusinessObject
	{
		#region Constants
		private static string	AgreementSummaryKey = GenerateKey.MakeKey("agreementSummary_5547A6D0-9766-487b-A051-B11113D4C326",GenerateKey.Agreement);
		private const string	TableName = "AgreementSummary";
		#endregion

		#region Instance Variables
		private DataRow	dataRow;
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the Access Level.
		/// </summary>
		public int AccessLevel
		{
			get
			{
				return (int)dataRow["AccessLevel"];
			}
		}

		/// <summary>
		/// Get the Activity Type. Returns an empty string if no activity type is associated with the agreement.
		/// </summary>
		public string ActivityType
		{
			get
			{
				object o = dataRow["ActivityType"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Get the Agreement ID.
		/// </summary>
		public int AgreementID 
		{
			get { return (int)dataRow["AgreementId"]; }
		}

		/// <summary>
		/// Get the AgreementSummary type. Returns an empty string if no type is associated with the agreement.
		/// </summary>
		public string AgreementType
		{
			get
			{
				object o = dataRow["AgreementType"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Get the AgreementSummary budget end date. Returns an empty string if no end date is associated with the agreement.
		/// </summary>
		public string BudgetEndDate
		{
			get
			{
				object o = dataRow["BudgetEndDate"];
				return (o == DBNull.Value) ? string.Empty : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Get the AgreementSummary budget start date. Returns an empty string if no start date is associated with the agreement.
		/// </summary>
		public string BudgetStartDate
		{
			get
			{
				object o = dataRow["BudgetStartDate"];
				return (o == DBNull.Value) ? "" : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Get the AgreementSummary Fund Number.
		/// </summary>
		public string FundNumber
		{
			get 
			{ 
				object o = dataRow["FundNumber"];
				return (o == DBNull.Value) ? "" : (string)o;
			}
		}

		/// <summary>
		/// Get the AgreementSummary PI name. Returns an empty string if no PI is associated with the agreement.
		/// </summary>
		public string PIName
		{
			get
			{
				object o = dataRow["PIName"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Get the AgreementSummary Project end date. Returns an empty string if no end date is associated with the agreement.
		/// </summary>
		public string ProjectEndDate
		{
			get
			{
				object o = dataRow["ProjectEndDate"];
				return (o == DBNull.Value) ? string.Empty : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Get the AgreementSummary Project start date. Returns an empty string if no start date is associated with the agreement.
		/// </summary>
		public string ProjectStartDate
		{
			get
			{
				object o = dataRow["ProjectStartDate"];
				return (o == DBNull.Value) ? string.Empty : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Get the AgreementSummary sponsor name.
		/// </summary>
		public string SponsorName
		{
			get { return (string)dataRow["SponsorName"]; }
		}

		/// <summary>
		/// Get the AgreementSummary status type. Returns an empty string if no status type is associated with the agreement.
		/// </summary>
		public string StatusType
		{
			get
			{
				object o = dataRow["StatusType"];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Get/Set the AgreementSummary short title.
		/// </summary>
		public string ShortTitle
		{
			get { return (string)dataRow["ShortTitle"]; }
			set { dataRow["ShortTitle"] = value;	}
		}

		/// <summary>
		/// Get/Set the AgreementSummary full title.
		/// </summary>
		public string Title
		{
			get { return (string)dataRow["Title"]; }
			set { dataRow["Title"] = value;	}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy, and save the DataRow in this instance.
		/// This is an example of a scenario where even though the AgreementSummary IS a business object, it DOES NOT
		/// use the DataContainer to store anything. The DataContainer is typically used when the BusinessObject is itself
		/// responsibly for loading the data for which it is the facacde. However, we have a scenario where the data for
		/// this object is already loaded (by the AgreementSummaryies object), and the AgreementSummary object simply
		/// provides the facade.
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="row">DataRow for the facade</param>
		public AgreementSummary(ICachePolicy cachePolicy, DataRow row) : base(cachePolicy)
		{
			dataRow = row;
		}
		#endregion

		#region Base Methods
		/// <summary>
		/// Cache this instance using the prevalent cache policy.
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(AgreementSummaryKey, this);
		}

		/// <summary>
		/// Remove this instance from the cache using the prevalent cache policy.
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(AgreementSummaryKey);
		}

		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		/// <param name="connection">Connection string to the database</param>
		/// <param name="agreementId">Optional arguments for load</param>
		public override void Load(string connectionString, params object[] args)
		{
			throw new Exception("AgreementSummary is not directly loadable");
		}
		#endregion
	}
}

